//
//  RegistSuccessViewController.m
//  YaoHeAPP
//
//  Created by xyh on 16/7/5.
//  Copyright © 2016年 mac. All rights reserved.
//

#import "RegistSuccessViewController.h"
#import "Masonry.h"
#import "CreateCompanyVC.h"
#import "Controller.h"
#import "CompanyInviteCodeViewController.h"
#import "FindCompanyViewController.h"
@interface RegistSuccessViewController ()
{
    NSInteger width;
    NSInteger height;
}
@property(nonatomic,strong) UIView *NoApplyView;
@property(nonatomic,strong) UIView *ApplyView;
@property(nonatomic,strong) UILabel*textLabel;
@end

@implementation RegistSuccessViewController

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [MobClick beginLogPageView:@"RegistSuccess"];
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [MobClick endLogPageView:@"RegistSuccess"];
}

- (void)viewDidLoad {
    [super viewDidLoad];

    //调一个背景色
    UIColor*backColor=[UIColor whiteColor];
    UIColor*alphColor=[backColor colorWithAlphaComponent:0.96];
    self.view.backgroundColor=alphColor;
    
    width=self.view.frame.size.width;
    height=self.view.frame.size.height;
    self.view.backgroundColor=bgVCcolor;
    //加一个导航条
    UIView*navcBar=[[UIView alloc]init];
    navcBar.backgroundColor=[UIColor colorWithRed:90.f/255.f green:191.f/255.f blue:219.f/255.f alpha:1];
    [self.view addSubview:navcBar];
    [self.view bringSubviewToFront:navcBar];
    [navcBar mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(0);   make.left.offset(0);
        make.height.offset(60);  make.right.offset(0);
    }];
    //导航条标题
    UILabel*titleLabel=[[UILabel alloc]init];
    titleLabel.text=@"注册成功";
    titleLabel.font=Font(17);
    titleLabel.textAlignment=NSTextAlignmentCenter;
    titleLabel.textColor=[UIColor whiteColor];
    [navcBar addSubview:titleLabel];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(25);
        make.left.offset(width/2-50);
        make.width.offset(100);
        make.height.offset(30);
    }];
    
//    //返回按钮
//    UIButton*leftButton=[UIButton buttonWithType:UIButtonTypeCustom];
//    [leftButton setBackgroundImage:[UIImage imageNamed:@"return"] forState:UIControlStateNormal];
//    [leftButton addTarget:self action:@selector(backLogin) forControlEvents:UIControlEventTouchUpInside];
//    [navcBar addSubview:leftButton];
//    [leftButton mas_makeConstraints:^(MASConstraintMaker*make) {
//        make.left.offset(6);
//        make.width.offset(30);
//        make.height.offset(28);
//        make.bottom.offset(-6);
//    }];
//    
    
    //右侧登录按钮
    UIButton*rightButton=[UIButton buttonWithType:UIButtonTypeCustom];
    [rightButton setTitle:@"首页" forState:UIControlStateNormal];
    rightButton.titleLabel.font=Font(14);
    [rightButton addTarget:self action:@selector(pushHomeView) forControlEvents:UIControlEventTouchUpInside];
    [navcBar addSubview:rightButton];
    [rightButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(-6);
        make.width.offset(60);
        make.height.offset(28);
        make.bottom.offset(-6);
    }];

    
    //注册成功的图片
    UIImageView*successImg=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"seccessful"]];
    [self.view addSubview:successImg];
    [successImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(navcBar.mas_bottom).offset(45);
        make.left.offset(width/2-33);
        make.height.offset(66*1.1);
        make.right.offset(-(width/2-33));
    }];
    
    UIView*backView=[[UIView alloc]init];
    [self.view addSubview:backView];
    [backView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(0);
        make.right.offset(0);
        make.top.equalTo(successImg.mas_bottom).offset(15);
        make.height.offset(25);
    }];
    //恭喜这两个字
    UILabel*label1=[[UILabel alloc]init];
    label1.text=@"恭喜";
    label1.textColor=[UIColor blackColor];
    [backView addSubview:label1];
    [label1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(0);
        make.bottom.offset(0);
        make.left.offset(width/2-118);
        make.width.offset(40);
    }];
    //显示电话号码的label
    UILabel*numberLab=[[UILabel alloc]init];
    numberLab.text=[NSString stringWithFormat:@"%@",self.RegistpeoplePhone];
    numberLab.textColor=RGBCOLOR(131, 188, 0);
    [backView addSubview:numberLab];
    [numberLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(label1.mas_right).offset(2);
        make.height.offset(25);
        make.width.offset(115);
        make.top.offset(0);
    }];
    //注册成功这几个字的label
    UILabel*label2=[[UILabel alloc]init];
    //    label2.backgroundColor=[UIColor yellowColor];
    label2.textColor=[UIColor blackColor];
    label2.text=@"注册成功!";
    [backView addSubview:label2];
    [label2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(numberLab.mas_right).offset(2);
        make.top.offset(0);
        make.height.offset(25);
        make.width.offset(80);
    }];
    
    
    
    //剩下的文字
    _textLabel=[[UILabel alloc]init];
    _textLabel.textColor=[UIColor grayColor];
    _textLabel.numberOfLines=0;
    _textLabel.textAlignment=NSTextAlignmentCenter;
    [self.view addSubview:_textLabel];
    [_textLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(0);
        make.right.offset(0);
        make.top.equalTo(backView.mas_bottom).offset(2);
        make.height.offset(50);
    }];

    
    if ([self.IS_APPLY isEqualToString:@"0"]) {
        //此处新增字段   0表示没有提交加入公司申请（要创建公司） 1表示提交加入公司申请
        _textLabel.text=@"欢迎加入吆喝!\n你还没有创建或加入任何公司!";
        
        _NoApplyView=[[UIView alloc]init];
        _NoApplyView.backgroundColor=[UIColor clearColor];
        [self.view addSubview:_NoApplyView];
        [_NoApplyView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_textLabel.mas_bottom).offset(10);
            make.left.offset(0);
            make.bottom.offset(0);
            make.right.offset(0);
        }];
        
            //剩下的文字
            UILabel *creatLabel=[[UILabel alloc]init];
            creatLabel.textColor=[UIColor grayColor];
            creatLabel.numberOfLines=0;
            creatLabel.textAlignment=NSTextAlignmentLeft;
            creatLabel.font=Font(12);
            creatLabel.text=@"加入公司可以使用更强大的功能";
            [_NoApplyView addSubview:creatLabel];
            [creatLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.offset(33);
                make.right.offset(-33);
                make.top.offset(2);
                make.height.offset(20);
            }];

    
            //创建公司
            UIButton*loginBtn=[UIButton buttonWithType:UIButtonTypeCustom];
            [loginBtn setTitle:@"创建公司" forState:UIControlStateNormal];
            UIImage*loginOldImg=[UIImage imageNamed:@"loginbutton"];
            UIImage*loginNewImg=[loginOldImg stretchableImageWithLeftCapWidth:15 topCapHeight:0];
            [loginBtn setBackgroundImage:loginNewImg forState:UIControlStateNormal];
            [loginBtn addTarget:self action:@selector(createCompany) forControlEvents:UIControlEventTouchUpInside];
            [_NoApplyView addSubview:loginBtn];
            [loginBtn mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(creatLabel.mas_bottom).offset(2);
                make.left.offset(33);
                make.right.offset(-33);
                make.height.offset(40);
            }];
        
        
            UILabel *addLabel=[[UILabel alloc]init];
            addLabel.textColor=[UIColor grayColor];
            addLabel.numberOfLines=0;
            addLabel.textAlignment=NSTextAlignmentLeft;
            addLabel.font=Font(12);
            addLabel.text=@"先看看有没有同事已经创建了公司";
            [_NoApplyView addSubview:addLabel];
            [addLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.offset(33);
                make.right.offset(-33);
                make.top.equalTo(loginBtn.mas_bottom).offset(10);
                make.height.offset(20);
            }];

        
            //如何加入公司按钮
            UIButton*registBtn=[UIButton buttonWithType:UIButtonTypeCustom];
            [registBtn setTitleColor:[UIColor colorWithRed:0.f/255.f green:179.f/255.f blue:249.f/255.f alpha:1] forState:UIControlStateNormal];
            [registBtn setTitle:@"查找公司" forState:UIControlStateNormal];
            UIImage*registOldImg=[UIImage imageNamed:@"ifaddbut_38"];
            UIImage*registNewImg=[registOldImg stretchableImageWithLeftCapWidth:19 topCapHeight:0];
            [registBtn setBackgroundImage:registNewImg forState:UIControlStateNormal];
            [registBtn addTarget:self action:@selector(queryCompanyBut) forControlEvents:UIControlEventTouchUpInside];
            [_NoApplyView addSubview:registBtn];
            [registBtn mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(addLabel.mas_bottom).offset(2);
                make.left.offset(33);
                make.right.offset(-33);
                make.height.offset(40);
            }];

        
            UIButton*addyaoqinmaBtn=[UIButton buttonWithType:UIButtonTypeCustom];
            [addyaoqinmaBtn setTitleColor:[UIColor colorWithRed:0.f/255.f green:179.f/255.f blue:249.f/255.f alpha:1] forState:UIControlStateNormal];
            [addyaoqinmaBtn setTitle:@"我有邀请码,立即加入企业" forState:UIControlStateNormal];
            addyaoqinmaBtn.titleLabel.font=Font(13);
            addyaoqinmaBtn.titleLabel.textAlignment=NSTextAlignmentLeft;
            [addyaoqinmaBtn addTarget:self action:@selector(addyaoqinmaCompany) forControlEvents:UIControlEventTouchUpInside];
            [_NoApplyView addSubview:addyaoqinmaBtn];
            [addyaoqinmaBtn mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(registBtn.mas_bottom).offset(10);
                make.left.offset(33);
                make.right.offset(-120);
                make.height.offset(20);
            }];

            UIImageView *jiantouImageV=[[UIImageView alloc]init ];
            jiantouImageV.image=[UIImage imageNamed:@"ic_arraw"];
            [_NoApplyView addSubview:jiantouImageV];
            [jiantouImageV mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(registBtn.mas_bottom).offset(12);
                make.left.equalTo(addyaoqinmaBtn.mas_right).offset(0);
                make.width.offset(10);
                make.height.offset(15);
            }];
        
    }else{
      
            _textLabel.text=@"欢迎加入吆喝!";
            
            _ApplyView=[[UIView alloc]init];
            _ApplyView.backgroundColor=[UIColor clearColor];
            [self.view addSubview:_ApplyView];
            [_ApplyView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(_textLabel.mas_bottom).offset(10);
                make.left.offset(0);
                make.bottom.offset(0);
                make.right.offset(0);
            }];

            //剩下的文字
            UILabel *creatLabel=[[UILabel alloc]init];
            creatLabel.textColor=[UIColor grayColor];
            creatLabel.numberOfLines=0;
            creatLabel.textAlignment=NSTextAlignmentLeft;
            creatLabel.font=Font(13);
            creatLabel.text=@"已给贵公司主管理员发送申请加入公司请求。\n主管理员同意加入公司后，您将拥有现货下单等高级权限";
            [_ApplyView addSubview:creatLabel];
            [creatLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.offset(33);
                make.right.offset(-33);
                make.top.offset(20);
                make.height.offset(80);
            }];

        
            //创建公司
            UIButton*phoneBtn=[UIButton buttonWithType:UIButtonTypeCustom];
            [phoneBtn setTitle:@"联系主管理员" forState:UIControlStateNormal];
            phoneBtn.backgroundColor=[UIColor colorWithRed:13.f/255.f green:107.f/255.f blue:180.f/255.f alpha:1];
            [phoneBtn addTarget:self action:@selector(calliphone) forControlEvents:UIControlEventTouchUpInside];
            [_ApplyView addSubview:phoneBtn];
            [phoneBtn mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(creatLabel.mas_bottom).offset(10);
                make.left.offset(50);
                make.right.offset(-50);
                make.height.offset(40);
            }];

    }
    
    
}

//点击创建公司进入创建公司页面
-(void)createCompany
{
    [MobClick event:@"createACompany"];
    
    CreateCompanyVC*creatVC=[CreateCompanyVC new];
    [self.navigationController pushViewController:creatVC animated:YES];
}

//查找公司的按钮
-(void)queryCompanyBut
{
    [MobClick event:@"joinTheCompany"];
    
    FindCompanyViewController*findCompanyViewController=[FindCompanyViewController new];
    [self.navigationController pushViewController:findCompanyViewController animated:NO];
    
}

////警告框的协议方法 下方两个按钮的索引
//- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
//{
//}

//通过邀请码加入公司
-(void)addyaoqinmaCompany{
   
    CompanyInviteCodeViewController *companyInviteCodeViewController=[CompanyInviteCodeViewController new];
    [self.navigationController pushViewController:companyInviteCodeViewController animated:YES];
    
}

//返回首页
-(void)pushHomeView{
    //进入主页
    RootTabBarViewController *rootTabBarViewController = [RootTabBarViewController rootViewController];
    [rootTabBarViewController changeRootViewControllerTo:0];
}

////返回登录界面
//- (void)backLogin {
//    
//    [self.navigationController popViewControllerAnimated:NO];
//}

-(void)calliphone{
    
    //进入打电话页面
    UIWebView *webview = [[UIWebView alloc] init];
//    [NSURL URLWithString:@"tel:4008850051"]
    NSString *urlst=[NSString stringWithFormat:@"tel:%@",self.MasterPhone];
    [webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlst]]];
    [self.view addSubview:webview];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
